package cn.aitrox.ry.service.auth.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.auth.dao.AuthGroupRoleDao;
import cn.aitrox.ry.service.auth.entity.AuthGroupRoleEntity;
import cn.aitrox.ry.service.auth.mapper.AuthGroupRoleMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AuthGroupRoleDaoImpl extends BaseDaoImpl<AuthGroupRoleEntity> implements AuthGroupRoleDao {

    @Autowired
    private AuthGroupRoleMapper mapper;

    @Override
    public void deleteByGroupId(Integer groupId) {
        mapper.deleteByGroupId(groupId);
    }

    @Override
    public void batchInsert(List<AuthGroupRoleEntity> list) {
        super.batchInsert(list, 1000, new MapperSqlCallback<AuthGroupRoleEntity>() {
            @Override
            public void batchInsert(List<AuthGroupRoleEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByGroupIdRoleIds(Integer groupId, List<Integer> roleIds) {
        mapper.deleteByGroupIdRoleIds(groupId, roleIds);
    }

    @Override
    public List<AuthGroupRoleEntity> findByGroupIds(List<Integer> groupIds) {
        if (ArrayUtil.isEmpty(groupIds)) {
            return new ArrayList<>();
        }
        return mapper.findByGroupIds(groupIds);
    }
}
